import {ElLoading} from 'element-plus'
import {nextTick} from 'vue'

/**
 * ElLoading 封装
 */
export default {
  loading: undefined,

  start(msg) {
    if (msg === undefined) {
      msg = 'loading'
    }
    this.loading = ElLoading.service({
      lock: true,
      text: msg,
      background: 'rgba(0, 0, 0, 0.7)',
    })
    return this
  },

  close() {
    if (this.loading !== undefined) {
      nextTick(() => {
        this.loading.close()
      }).then(() => {
        console.log('close my loading')
      })
    }
  },
}
